With destructuring declarations, a Kotlin expression is decomposed into individual properties. Normally, an expression evaluates to a single object, but the destructuring converts that one object into several.

From a syntax standpoint, just have the multiple properties listed on the left-hand side of the assignment operator (=) wrapped in parentheses.

Then, the first property will be assigned the value of calling component1() on the object returned by the expression. The second property will be assigned the value of calling component2() on the object returned by the expression. And so on.

In addition to some built-in Kotlin classes supporting these "component" functions (e.g., Pair), a data class code-generates those functions for you, with the numbers corresponding to the order of the parameters in the data class primary constructor.

You can learn more about this in:
Run Edit